package com.qianli.cashmama.trade.dao;

import com.fqgj.common.api.Page;
import com.fqgj.common.base.BaseMapper;
import com.qianli.cashmama.trade.entity.TTradeEntity;
import com.qianli.cashmama.trade.vo.LoanAgainNotificationUserVO;

import java.util.List;

/**
 * User: sm
 * Date: 2017-07-20
 * Time: 19:47:54.184
 */

public interface TTradeDao extends BaseMapper<TTradeEntity> {

    /**
     * @param tradeNo
     * @return
     */
    TTradeEntity selectOneByTradeNo(String tradeNo);

    /**
     * @param tTradeEntity
     * @return
     */
    Integer updateByTradeNo(TTradeEntity tTradeEntity);

    /**
     * 查询当前用户在指定类目下的最近的一笔交易
     *
     * @param productCategory
     * @param userCode
     * @return
     */
    TTradeEntity selectOneByUserCodeAndProductCategory(String productCategory, String userCode);

    List<TTradeEntity> selectListByCondition(String merchantCode, String userCode, Integer orderStatus);

    /**
     * 根据订单状态和用户code查询列表
     *
     * @param orderStatus
     * @param userCode
     * @return
     */
    List<TTradeEntity> selectListByUserCodeAndOrderStatus(Integer orderStatus, String userCode);

    /**
     * 获取用户当前活跃的最新的交易
     *
     * @param userCode
     * @return
     */
    TTradeEntity selectOneActiveByUserCode(String userCode);

    /**
     * @param userCode
     * @return
     */
    int countByUserCode(String userCode, String productCategory);

    /**
     * @param userCode
     * @param productCategory
     * @param page
     * @param closed
     * @param closedType
     * @return
     */
    List<TTradeEntity> selectListByUserCodeAndProductCategory(String userCode, String productCategory, Page page, Boolean closed, Integer closedType);

    /**
     * @param userCode
     * @param productCategory
     * @return
     */
    List<TTradeEntity> selectListByUserCodeAndProductCategoryAndStatus(String userCode, String productCategory);

    /**
     * 根据userCodes查询交易列表
     *
     * @param userCodes
     * @return
     */
    List<TTradeEntity> selectListByUserCodes(List<String> userCodes);

    /**
     * @param userCode
     * @param page
     * @return
     */
    List<TTradeEntity> selectListByUserCode(String userCode, Page page);

    List<TTradeEntity> selectListByUserCode(String userCode);

    /**
     * @param tradeNos
     * @param page
     * @return
     */
    List<TTradeEntity> selectListByTradeNosAndPage(List<String> tradeNos, Page page);


    /**
     * @param userCodes
     * @param tradeStatusList
     * @param tradeNo
     * @return
     */
    List<TTradeEntity> selectListByUserCodesAndStatusAndTradeNo(List<String> userCodes, List<Integer> tradeStatusList, String tradeNo, String productCategory, Page page);


    /**
     * @param orderIds
     * @return
     */
    List<TTradeEntity> selectByOrderIds(List<Long> orderIds);

    List<TTradeEntity> selectByOrderStatus(Integer orderStatus);

    /**
     * @param tradeNos
     * @return
     */
    List<TTradeEntity> selectListByTradeNos(List<String> tradeNos);


    /**
     * @param productCode
     * @param userCode
     * @return
     */
    TTradeEntity selectOneByUserCodeAndProductCode(String productCode, String userCode);

    /**
     * 查询按时还款后没有继续借款的用户
     *
     * @return
     */
    List<LoanAgainNotificationUserVO> selectLoanAgainNotificationUser();

    int countOrdersByUserCode(String userCode, Boolean closed);

    /**
     * 计算当前订单数量
     *
     * @param categoryCode
     * @return
     */
    int countCurrentDateOrdersByCategoryCode(String categoryCode);


    List<TTradeEntity> getFirstPushWaittingList(Page page);

    List<TTradeEntity> getSecondPushWaittingList(Page page);

    List<TTradeEntity> getThirdPushWaittingList(Page page);


    List<TTradeEntity> getListByProductCategory(String productCategory);

    List<TTradeEntity> getOldUnpaidTradeListByMobile(String mobile);


    void copyInsert(TTradeEntity entity);

    Integer  getWhiteCount(String productCategory,String mobile,Integer type);
}